package com.example.androidxtest.lazy;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.Window;

import com.example.androidxtest.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class androidxLazyActivity extends AppCompatActivity {
    private ViewPager vp;
    private TabLayout tab;
    ArrayList<Fragment> fragments;
    ArrayList<String> titles;
    FragmentA fragmentA;
    FragmentB fragmentB;
    FragmentC fragmentC;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //取消标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //取消状态栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_mainx);

        vp = (ViewPager) findViewById(R.id.vp);
        tab = (TabLayout) findViewById(R.id.tab);

        fragmentA = new FragmentA();
        fragmentB = new FragmentB();
        fragmentC = new FragmentC();
        fragments = new ArrayList<>();
        fragments.add(fragmentA);
        fragments.add(fragmentB);
        fragments.add(fragmentC);

        titles = new ArrayList<>();
        titles.add("A");
        titles.add("B");
        titles.add("C");


        FPAdater fpAdater = new FPAdater(getSupportFragmentManager(), fragments, titles);

        vp.setAdapter(fpAdater);
        tab.setupWithViewPager(vp);//与viewpager联系起来
    }
}